//
//  PAParamVC.m
//  PilotSeries
//
//  Created by 黄立强 on 16/7/4.
//  Copyright © 2016年 leon.huang. All rights reserved.
//

#import "PAParamVC.h"

@interface PAParamVC ()

@end

@implementation PAParamVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"Paramters Setting";
     [self initializeForm];
    self.navigationItem.rightBarButtonItem  = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(configData:)];

}

-(void)initializeForm{
    XLFormDescriptor * form;
    XLFormSectionDescriptor * section;
    XLFormRowDescriptor * row;
    
    form = [XLFormDescriptor formDescriptor];
    
    section = [XLFormSectionDescriptor formSectionWithTitle:nil];
    
    
    
    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"business.hours" rowType:XLFormRowDescriptorTypeMultipleSelector title:@"businesshours"];
    row.selectorOptions = @[@"9:00-11.45", @"13:30-16.30"];
    row.value = @[@"9:00-11.45", @"13:30-16.30"];
    
    [section addFormRow:row];
    //chart_ownaxis
    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"chart.ownaxis" rowType:XLFormRowDescriptorTypeBooleanSwitch title:@"chart.ownaxis"];
    row.value = @NO;
    [row.cellConfigAtConfigure setObject:[UIColor redColor] forKey:@"switchControl.onTintColor"];
    [section addFormRow:row];
    
    // chart_percentile
    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"chart.percentile" rowType:XLFormRowDescriptorTypeText title:@"chart_percentile"];
    [row.cellConfigAtConfigure setObject:@(NSTextAlignmentRight) forKey:@"textField.textAlignment"];
    row.value =@"0.95";
    [section addFormRow:row];
    
    // chart_percentile_expansion
    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"chart.percentile.expansion" rowType:XLFormRowDescriptorTypeText title:@"chart.percentile_expansion"];
    [row.cellConfigAtConfigure setObject:@(NSTextAlignmentRight) forKey:@"textField.textAlignment"];
    row.value =@"0.1";
    [section addFormRow:row];
    
    //chart_rollingwindow
    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"chart.rollingwindow" rowType:XLFormRowDescriptorTypeText title:@"chart.rollingwindow"];
    [row.cellConfigAtConfigure setObject:@(NSTextAlignmentRight) forKey:@"textField.textAlignment"];
    row.value =@"all";
    [section addFormRow:row];
    
    //liveview_include_recent_points
    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"liveview.include.recent.points" rowType:XLFormRowDescriptorTypeText title:@"liveview.include.recent.points"];
    [row.cellConfigAtConfigure setObject:@(NSTextAlignmentRight) forKey:@"textField.textAlignment"];
    row.value =@"5";
    [section addFormRow:row];
    //percentile_recalc_interval
    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"percentile.recalc.interval" rowType:XLFormRowDescriptorTypeText title:@"percentile.recalc.interval"];
    [row.cellConfigAtConfigure setObject:@(NSTextAlignmentRight) forKey:@"textField.textAlignment"];
    row.value =@"300";
    [section addFormRow:row];
    
    //chart_ownaxis
    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"window.frameless" rowType:XLFormRowDescriptorTypeBooleanSwitch title:@"window.frameless"];
    row.value = @YES;
    [row.cellConfigAtConfigure setObject:[UIColor redColor] forKey:@"switchControl.onTintColor"];
    [section addFormRow:row];
    
    
    [form addFormSection:section];
    self.form = form;
}

-(void)configData:(UIBarButtonItem *)buttonItem{
    
    NSDictionary *dic = [self formValues];
    NSMutableDictionary *mParms = [dic mutableCopy];
    NSArray *hours =dic[@"business.hours"];
    mParms[@"business.hours"] = [hours componentsJoinedByString: @","];
    if ([dic[@"chart.ownaxis"] isKindOfClass:[NSNull class]] || [dic[@"chart.ownaxis"] isEqual:@0]) {
         mParms[@"chart.ownaxis"] = @NO;
    }else{
         mParms[@"chart.ownaxis"] = @YES;
        
    }
    if ([dic[@"window.frameless"] isKindOfClass:[NSNull class]] || [dic[@"window.frameless"] isEqual:@0]) {
       mParms[@"window.frameless"] = @NO;
    }else{
      mParms[@"window.frameless"] = @YES;
        
    }
    if (self.block) {
        self.block(mParms);
    }
    [self.navigationController popViewControllerAnimated:YES];
}
@end
